<template>
<div class="form">
  <slot></slot>
</div>
</template>

<script>
import schema from "async-validator";
export default {
  props: {
    model: {
      type: Object
    },
    rules: Object
  },
  computed: {
    validFields() {
      return this.$children.filter(item => item.prop)
    }
  },
  methods: {
    validate(cb) {
      let validator = new schema(this.rules)
      const arr = this.validFields.map(item => item.validate())
      Promise.all(arr).then(() => cb(true)).catch(err => cb(false))
    }
  }
}
</script>
